/* 
 * File:   Rectangle.cpp
 * Author: lucia
 * 
 * Created on 17 de octubre de 2014, 20:37
 */

#include "Rectangle.h"

Rectangle::Rectangle(struct ObjectInit data, SDL_Renderer *render, int pixelWidth, int pixelHeight, int unitWidth, int unitHeight) {
    this->data = data;

    //harcodeado
    this->data.x = 500;
    this->data.y = 500;
    this->data.height = 200;
    this->data.width = 200;
    this->data.rot = 0;

    //    myLogFile->getInstance(MY_LOG_MODE);
    this->dot = new Dot(this->data.x, this->data.y, this->data.width, this->data.height);
    this->gRenderer = render;
    this->loadMedia();

}

void Rectangle::draw() {

    //faltaria donde se vuelve a setear data 
    //segun lo que viene del Server
    b2Vec2* pos;
    b2Vec2* size;
    this->dot->setPos(this->data.x, this->data.y);
    this->dot->setSize(this->data.width, this->data.height);
//    pos = this->dot->dotWorldToPixels();
    
    size = this->dot->sizeDotWorldToPixels();

    SDL_Rect* settings = new SDL_Rect();
    settings->w = size->x;
    settings->h = size->y;
//     settings->x = pos->x;
//    settings->y = pos->y;
    settings->x = this->data.x;
    settings->y = this->data.y;

    SDL_RenderCopyEx(gRenderer, image->getTexture(), NULL, settings, this->data.rot, NULL, SDL_FLIP_NONE);
    delete settings;

}

void Rectangle::loadMedia() {

    this->image = new SBSImage();
    this->image->loadMedia("Img/rectangle2.png", &gRenderer);

}

Rectangle::~Rectangle() {
    delete this->image;
    delete this->dot;
}

